#include "Train.h"

class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int res = 0, l = 0, r = 0;
        int zero_num = 0;
        while (r < nums.size())
        {
            if (nums[r] == 0) zero_num++;

            while (zero_num > k)
            {
                if (nums[l++] == 0)zero_num--;
            }
            res = max(r - l + 1, res);
            r++;
        }
        return res;
    }
};